/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * dlSource.java
 *
 * Created on Aug 11, 2010, 4:46:14 PM
 */
package Gui;

import BusinessLogic.BackGroundUtility;
import BusinessLogic.DateUtility;
import BusinessLogic.ExhibitorManagement;
import DTO.Exhibitor;
import DTO.ImportantDate;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Administrator
 */
public class DLExhibitor extends javax.swing.JDialog {

    private boolean flag = false;
    private ExhibitorManagement ExhibitorMag;
    private Vector<Exhibitor> subList;
    private Vector<Exhibitor> listExhibitor;
    private DefaultTableModel model;
    private String sortBy = "id";
    private String order = "Desc";
    private int index = 0;

    /** Creates new form dlSource */
    public DLExhibitor(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        //set background
        ImagePanel iPanel = new ImagePanel(BackGroundUtility.getImage());
        getContentPane().add(iPanel);
        //setlocation for application
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension dim = toolkit.getScreenSize();
        Dimension dimApp = getSize();
        int pointX = (dim.width - dimApp.width) / 2;
        int pointY = (dim.height - dimApp.height) / 2 - 10;
        setLocation(pointX, pointY);

        //Create object zone management to access database
        ExhibitorMag = new ExhibitorManagement();
        //call method load list ImportantDate
        ExhibitorMag.loadImportDate();
        //call method load listExhibitor into table
        loadExhibitor();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        rdStatus = new javax.swing.ButtonGroup();
        rdPaid = new javax.swing.ButtonGroup();
        rdConfirm = new javax.swing.ButtonGroup();
        pnBackground = new javax.swing.JPanel();
        pnContent = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtID = new javax.swing.JTextField();
        txtName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtCompany = new javax.swing.JTextField();
        txtMoney = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        txtFax = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        rdStatusYes = new javax.swing.JRadioButton();
        txtPhone = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        rdStatusNo = new javax.swing.JRadioButton();
        rdConfirmYes = new javax.swing.JRadioButton();
        rdConfirmNo = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtContactSend = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtLastChange = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtPaid = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtContactReturn = new javax.swing.JTextField();
        lblEditContReturn = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtAddress = new javax.swing.JTextArea();
        lblHistory = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        lblPayment = new javax.swing.JLabel();
        lblEditContSent = new javax.swing.JLabel();
        lblEditLastChange = new javax.swing.JLabel();
        lblEditPaid = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        btnPrev = new javax.swing.JButton();
        btnNext = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        btnSave = new javax.swing.JButton();
        btnAdd = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbExhibitor = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        txtSearch = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        cbSort = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        cbOrder = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Exhibitor Management");

        pnBackground.setBackground(new java.awt.Color(0, 102, 102));
        pnBackground.setOpaque(false);

        pnContent.setBackground(new java.awt.Color(255, 255, 255));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Exhibitor Management"));
        jPanel1.setLayout(null);

        jLabel4.setText("id");
        jPanel1.add(jLabel4);
        jLabel4.setBounds(20, 30, 40, 14);

        txtID.setEditable(false);
        jPanel1.add(txtID);
        txtID.setBounds(80, 30, 90, 19);
        jPanel1.add(txtName);
        txtName.setBounds(80, 60, 190, 19);

        jLabel2.setText("Name");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(20, 60, 40, 14);

        jLabel5.setText("Company");
        jPanel1.add(jLabel5);
        jLabel5.setBounds(20, 90, 48, 14);
        jPanel1.add(txtCompany);
        txtCompany.setBounds(80, 90, 190, 19);
        jPanel1.add(txtMoney);
        txtMoney.setBounds(80, 150, 110, 19);

        jLabel6.setText("Money");
        jPanel1.add(jLabel6);
        jLabel6.setBounds(20, 150, 50, 14);
        jPanel1.add(txtEmail);
        txtEmail.setBounds(80, 210, 190, 19);
        jPanel1.add(txtFax);
        txtFax.setBounds(80, 240, 190, 19);

        jLabel7.setText("Phone");
        jPanel1.add(jLabel7);
        jLabel7.setBounds(20, 270, 40, 14);

        jLabel3.setText("Fax");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(20, 240, 40, 14);

        jLabel1.setText("Email");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(20, 210, 40, 14);

        jLabel9.setText("Status");
        jPanel1.add(jLabel9);
        jLabel9.setBounds(20, 120, 80, 14);

        rdStatus.add(rdStatusYes);
        rdStatusYes.setText("JOIN");
        jPanel1.add(rdStatusYes);
        rdStatusYes.setBounds(80, 120, 50, 23);
        jPanel1.add(txtPhone);
        txtPhone.setBounds(80, 270, 190, 19);

        jLabel10.setText("Address");
        jPanel1.add(jLabel10);
        jLabel10.setBounds(320, 30, 40, 14);

        rdStatus.add(rdStatusNo);
        rdStatusNo.setSelected(true);
        rdStatusNo.setText("NOT JOIN");
        jPanel1.add(rdStatusNo);
        rdStatusNo.setBounds(140, 120, 80, 23);

        rdConfirm.add(rdConfirmYes);
        rdConfirmYes.setText("Yes");
        jPanel1.add(rdConfirmYes);
        rdConfirmYes.setBounds(90, 180, 43, 20);

        rdConfirm.add(rdConfirmNo);
        rdConfirmNo.setSelected(true);
        rdConfirmNo.setText("No");
        jPanel1.add(rdConfirmNo);
        rdConfirmNo.setBounds(140, 180, 39, 20);

        jLabel11.setText("[mm/dd/yyyy]");
        jPanel1.add(jLabel11);
        jLabel11.setBounds(410, 130, 70, 14);

        jLabel12.setText("Contact send");
        jPanel1.add(jLabel12);
        jLabel12.setBounds(320, 150, 80, 14);

        txtContactSend.setEditable(false);
        jPanel1.add(txtContactSend);
        txtContactSend.setBounds(410, 150, 150, 19);

        jLabel13.setText("Last Change");
        jPanel1.add(jLabel13);
        jLabel13.setBounds(320, 180, 60, 14);

        txtLastChange.setEditable(false);
        jPanel1.add(txtLastChange);
        txtLastChange.setBounds(410, 180, 150, 19);

        jLabel14.setText("Paid");
        jPanel1.add(jLabel14);
        jLabel14.setBounds(320, 210, 60, 14);

        txtPaid.setEditable(false);
        jPanel1.add(txtPaid);
        txtPaid.setBounds(410, 210, 150, 19);

        jLabel15.setText("Contact Return");
        jPanel1.add(jLabel15);
        jLabel15.setBounds(320, 240, 80, 14);

        txtContactReturn.setEditable(false);
        jPanel1.add(txtContactReturn);
        txtContactReturn.setBounds(410, 240, 150, 19);

        lblEditContReturn.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblEditContReturn.setForeground(new java.awt.Color(0, 70, 213));
        lblEditContReturn.setText("<html> <u>Edit</u> </html>");
        lblEditContReturn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblEditContReturnMousePressed(evt);
            }
        });
        jPanel1.add(lblEditContReturn);
        lblEditContReturn.setBounds(570, 240, 30, 14);

        txtAddress.setColumns(20);
        txtAddress.setRows(5);
        jScrollPane2.setViewportView(txtAddress);

        jPanel1.add(jScrollPane2);
        jScrollPane2.setBounds(410, 30, 190, 90);

        lblHistory.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblHistory.setForeground(new java.awt.Color(0, 70, 213));
        lblHistory.setText("<html>\n<u>View History</u>\n</html>");
        lblHistory.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblHistoryMousePressed(evt);
            }
        });
        jPanel1.add(lblHistory);
        lblHistory.setBounds(180, 30, 80, 14);

        jLabel18.setText("Print badge");
        jPanel1.add(jLabel18);
        jLabel18.setBounds(20, 180, 70, 14);

        lblPayment.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblPayment.setForeground(new java.awt.Color(0, 0, 255));
        lblPayment.setText("Payment");
        lblPayment.setEnabled(false);
        lblPayment.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblPaymentMousePressed(evt);
            }
        });
        jPanel1.add(lblPayment);
        lblPayment.setBounds(200, 150, 60, 20);

        lblEditContSent.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblEditContSent.setForeground(new java.awt.Color(0, 70, 213));
        lblEditContSent.setText("<html> <u>Edit</u> </html>");
        lblEditContSent.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblEditContSentMousePressed(evt);
            }
        });
        jPanel1.add(lblEditContSent);
        lblEditContSent.setBounds(570, 150, 30, 14);

        lblEditLastChange.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblEditLastChange.setForeground(new java.awt.Color(0, 70, 213));
        lblEditLastChange.setText("<html> <u>Edit</u> </html>");
        lblEditLastChange.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblEditLastChangeMousePressed(evt);
            }
        });
        jPanel1.add(lblEditLastChange);
        lblEditLastChange.setBounds(570, 180, 30, 14);

        lblEditPaid.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblEditPaid.setForeground(new java.awt.Color(0, 70, 213));
        lblEditPaid.setText("<html> <u>Edit</u> </html>");
        lblEditPaid.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                lblEditPaidMousePressed(evt);
            }
        });
        jPanel1.add(lblEditPaid);
        lblEditPaid.setBounds(570, 210, 30, 14);

        jPanel2.setLayout(null);

        btnPrev.setText("Prev");
        btnPrev.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrevActionPerformed(evt);
            }
        });
        jPanel2.add(btnPrev);
        btnPrev.setBounds(140, 10, 70, 23);

        btnNext.setText("Next");
        btnNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextActionPerformed(evt);
            }
        });
        jPanel2.add(btnNext);
        btnNext.setBounds(230, 10, 70, 23);

        jButton3.setText("First");
        jPanel2.add(jButton3);
        jButton3.setBounds(320, 10, 70, 23);

        jButton4.setText("Last");
        jPanel2.add(jButton4);
        jButton4.setBounds(410, 10, 70, 23);

        btnSave.setText("Save");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });
        jPanel2.add(btnSave);
        btnSave.setBounds(140, 50, 70, 23);

        btnAdd.setText("Add");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        jPanel2.add(btnAdd);
        btnAdd.setBounds(230, 50, 70, 23);

        jButton7.setText("Del");
        jPanel2.add(jButton7);
        jButton7.setBounds(320, 50, 70, 23);

        jButton8.setText("Cancel");
        jPanel2.add(jButton8);
        jButton8.setBounds(410, 50, 70, 23);

        tbExhibitor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tbExhibitor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tbExhibitorMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(tbExhibitor);

        txtSearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtSearchKeyReleased(evt);
            }
        });
        txtSearch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                txtSearchMouseReleased(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel16.setText("Look for");

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel17.setText("Sort by");

        cbSort.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ID", "Name" }));
        cbSort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbSortActionPerformed(evt);
            }
        });

        jLabel19.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel19.setText("Order");

        cbOrder.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Asc", "Desc" }));
        cbOrder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbOrderActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(63, 63, 63)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbSort, 0, 97, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel19)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(cbSort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(cbOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout pnContentLayout = new javax.swing.GroupLayout(pnContent);
        pnContent.setLayout(pnContentLayout);
        pnContentLayout.setHorizontalGroup(
            pnContentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnContentLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnContentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE))
                .addContainerGap())
        );
        pnContentLayout.setVerticalGroup(
            pnContentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnContentLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 302, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout pnBackgroundLayout = new javax.swing.GroupLayout(pnBackground);
        pnBackground.setLayout(pnBackgroundLayout);
        pnBackgroundLayout.setHorizontalGroup(
            pnBackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnBackgroundLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnContent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pnBackgroundLayout.setVerticalGroup(
            pnBackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnBackgroundLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnContent, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        getContentPane().add(pnBackground, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void lblEditContReturnMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblEditContReturnMousePressed
        // TODO add your handling code here:
        txtContactReturn.setEditable(true);
}//GEN-LAST:event_lblEditContReturnMousePressed

    private void btnPrevActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrevActionPerformed
        // TODO add your handling code here:
        if (index > 0) {
            //Display a Zone
            displayObject(--index);
        }
}//GEN-LAST:event_btnPrevActionPerformed

    private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextActionPerformed
        // TODO add your handling code here:
        if (index + 1 < listExhibitor.size()) {
            //Display a Zone
            displayObject(++index);
        }
    }//GEN-LAST:event_btnNextActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        //gettext from textfiels
        if (checkEmpty() == false) {
            JOptionPane.showMessageDialog(this, "a TextField is Empty!!!");
            return;
        }
        String name = txtName.getText();
        String address = txtAddress.getText();
        String company = txtCompany.getText();
        String email = txtEmail.getText();
        String fax = txtFax.getText();
        float money = Float.parseFloat(txtMoney.getText());
        String phone = txtPhone.getText();
        String idExhibitor = txtID.getText();
        int confirm = 0;
        if (rdConfirmYes.isSelected()) {
            confirm = 1;
        }

        Exhibitor exhibitor = new Exhibitor(idExhibitor, name, company, money, 0, email, fax, phone, address, confirm, 1);

        //Create object importantdate
        String contReturn = txtContactReturn.getText();
        String contSend = txtContactSend.getText();
        String paid = txtPaid.getText();
        String lastChange = txtLastChange.getText();

        ImportantDate im = new ImportantDate(idExhibitor, lastChange, paid, contSend, contReturn);
        if (flag) {
            if (!ExhibitorMag.checkName(name)) {
                JOptionPane.showMessageDialog(this, "There is that name in database!!! Please enter other name");
                return;
            }
            ExhibitorMag.insert(exhibitor);
            ExhibitorMag.insert(im);
            flag = false;
        } else {
            ExhibitorMag.update(exhibitor);
            ExhibitorMag.update(im);
        }

        
        //call method load again
        ExhibitorMag.loadImportDate();
        //load listExhibitor again
        index = 0;
        loadExhibitor();
}//GEN-LAST:event_btnSaveActionPerformed

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        //call method clearText()
        clearText();
        //method createID automatic create new id
        String id = ExhibitorMag.createID();
        txtID.setText(id);
        //call method get today
        String today = DateUtility.today();
        txtContactSend.setText(today);
        flag = true;
}//GEN-LAST:event_btnAddActionPerformed

    private void lblHistoryMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblHistoryMousePressed
        // TODO add your handling code here:
        DLHistory his = new DLHistory(null, true, ExhibitorMag, listExhibitor.get(index));
        his.setVisible(true);
    }//GEN-LAST:event_lblHistoryMousePressed

    private void lblPaymentMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblPaymentMousePressed
        // TODO add your handling code here:   
        if (lblPayment.isEnabled()) {

            int a = JOptionPane.showConfirmDialog(this, "Do you want payment for this Exhibitor?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if (a == JOptionPane.YES_OPTION) {
                String today = DateUtility.today();
                txtPaid.setText(today);
                //call method update
                ExhibitorMag.paidMoney(txtID.getText(), today);
                lblPayment.setEnabled(false);
                //call method load list ImportantDate
                ExhibitorMag.loadImportDate();
                //call method load listExhibitor into table
                loadExhibitor();
            }
        }

    }//GEN-LAST:event_lblPaymentMousePressed

    private void lblEditContSentMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblEditContSentMousePressed
        // TODO add your handling code here:
        txtContactSend.setEditable(true);
    }//GEN-LAST:event_lblEditContSentMousePressed

    private void lblEditLastChangeMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblEditLastChangeMousePressed
        // TODO add your handling code here:
        txtLastChange.setEditable(true);
    }//GEN-LAST:event_lblEditLastChangeMousePressed

    private void lblEditPaidMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblEditPaidMousePressed
        // TODO add your handling code here:
        txtPaid.setEditable(true);
    }//GEN-LAST:event_lblEditPaidMousePressed

    private void txtSearchMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtSearchMouseReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSearchMouseReleased

    private void txtSearchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSearchKeyReleased
        // TODO add your handling code here:
        subList = new Vector<Exhibitor>();
        String name = txtSearch.getText();
        name = name.toUpperCase().trim();

        for (Exhibitor exhibitor : listExhibitor) {
            String nameEx = exhibitor.getName();
            nameEx = nameEx.toUpperCase().trim();

            if (nameEx.contains(name)) {
                subList.add(exhibitor);
            }
        }
        setModel(subList);
    }//GEN-LAST:event_txtSearchKeyReleased

    private void tbExhibitorMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbExhibitorMousePressed
        // TODO add your handling code here:
        index = tbExhibitor.getSelectedRow();
        displayObject(index);
    }//GEN-LAST:event_tbExhibitorMousePressed

    private void cbSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortActionPerformed
        // TODO add your handling code here:
        JComboBox cb = (JComboBox) evt.getSource();
        sortBy = (String) cb.getSelectedItem();
        //call method sort
        sortList();
    }//GEN-LAST:event_cbSortActionPerformed

    private void sortList() {
        Collections.sort(subList, new Comparator<Exhibitor>() {

            public int compare(Exhibitor ex1, Exhibitor ex2) {
                if (sortBy.equalsIgnoreCase("id")) {
                    if (order.equalsIgnoreCase("Asc")) {
                        return ex1.getId().compareToIgnoreCase(ex2.getId());
                    } else {
                        return ex2.getId().compareToIgnoreCase(ex1.getId());
                    }

                } else if (sortBy.equalsIgnoreCase("Name")) {

                    if (order.equalsIgnoreCase("Asc")) {
                        return ex1.getName().compareToIgnoreCase(ex2.getName());
                    } else {
                        return ex2.getName().compareToIgnoreCase(ex1.getName());
                    }
                }
                return 0;
            }
        });
        //display table again
        setModel(subList);
    }
    private void cbOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbOrderActionPerformed
        // TODO add your handling code here:
        JComboBox cb = (JComboBox) evt.getSource();
        order = (String) cb.getSelectedItem();

        //call method sort
        sortList();
    }//GEN-LAST:event_cbOrderActionPerformed

    public void setModel(Vector<Exhibitor> list) {
        model = new DefaultTableModel(null, new Object[]{"ID", "Name", "Company", "PaidStatus", "Money", "Status", "Email", "Fax", "Phone", "Address"});
        tbExhibitor.setModel(model);

        for (Exhibitor e : list) {
            Vector rowData = new Vector();
            rowData.add(e.getId());
            rowData.add(e.getName());
            rowData.add(e.getCompany());
            rowData.add(e.getPaidStatus());
            rowData.add(e.getMoney());
            rowData.add(e.getStatus());
            rowData.add(e.getEmail());
            rowData.add(e.getFax());
            rowData.add(e.getPhone());
            rowData.add(e.getAddress());

            model.addRow(rowData);
        }
    }

    public void loadExhibitor() {
        //load listExhibitor
        listExhibitor = ExhibitorMag.loadExhibitor();
        //pass
        subList = listExhibitor;
        //display table
        setModel(listExhibitor);
        //Display a Zone
        displayObject(index);
    }

    private void displayObject(int index) {
        Exhibitor e = ExhibitorMag.getByIndex(index);

        //set values for textfiels
        txtID.setText(e.getId());
        txtName.setText(e.getName());
        txtCompany.setText(e.getCompany());
        txtEmail.setText(e.getEmail());
        if (e.getStatus() == 1) {
            rdStatusYes.setSelected(true);
        } else {
            rdStatusNo.setSelected(true);
        }
        //visible lable payment
        if (e.getPaidStatus() == 1 || e.getStatus() == 0) {
            lblPayment.setEnabled(false);
            txtMoney.setText("" + e.getMoney());
        } else {
            lblPayment.setEnabled(true);
            txtMoney.setText("-" + e.getMoney());
        }
        txtFax.setText(e.getFax());
        txtPhone.setText(e.getPhone());
        txtAddress.setText(e.getAddress());
        txtMoney.setText(e.getMoney() + "");

        if (ExhibitorMag.countListDate() > 0) {
            ImportantDate im = ExhibitorMag.getbyID(e.getId());
            txtContactReturn.setText(im.getContReturnDate());
            txtContactSend.setText(im.getContSendDate());
            txtLastChange.setText(im.getLastChangeDate());
            txtPaid.setText(im.getPaidDate());
        }

    }

    /**
     * clear text on textfields
     */
    private void clearText() {
        txtAddress.setText("");
        txtCompany.setText("");
        txtContactReturn.setText("");
        txtContactSend.setText("");
        txtEmail.setText("");
        txtFax.setText("");
        txtLastChange.setText("");
        txtMoney.setText("");
        txtName.setText("");
        txtPaid.setText("");
        txtPhone.setText("");
    }

    public boolean checkEmpty() {
        boolean test = true;
        if (txtID.getText().equals("")) {
            test = false;
        }
        if (txtName.getText().equals("")) {
            test = false;
        }
        if (txtCompany.getText().equals("")) {
            test = false;
        }
        if (txtEmail.getText().equals("")) {
            test = false;
        }
        if (txtFax.getText().equals("")) {
            test = false;
        }
        if (txtMoney.getText().equals("")) {
            test = false;
        }
        if (txtPhone.getText().equals("")) {
            test = false;
        }



        return test;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnNext;
    private javax.swing.JButton btnPrev;
    private javax.swing.JButton btnSave;
    private javax.swing.JComboBox cbOrder;
    private javax.swing.JComboBox cbSort;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblEditContReturn;
    private javax.swing.JLabel lblEditContSent;
    private javax.swing.JLabel lblEditLastChange;
    private javax.swing.JLabel lblEditPaid;
    private javax.swing.JLabel lblHistory;
    private javax.swing.JLabel lblPayment;
    private javax.swing.JPanel pnBackground;
    private javax.swing.JPanel pnContent;
    private javax.swing.ButtonGroup rdConfirm;
    private javax.swing.JRadioButton rdConfirmNo;
    private javax.swing.JRadioButton rdConfirmYes;
    private javax.swing.ButtonGroup rdPaid;
    private javax.swing.ButtonGroup rdStatus;
    private javax.swing.JRadioButton rdStatusNo;
    private javax.swing.JRadioButton rdStatusYes;
    private javax.swing.JTable tbExhibitor;
    private javax.swing.JTextArea txtAddress;
    private javax.swing.JTextField txtCompany;
    private javax.swing.JTextField txtContactReturn;
    private javax.swing.JTextField txtContactSend;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtFax;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtLastChange;
    private javax.swing.JTextField txtMoney;
    private javax.swing.JTextField txtName;
    private javax.swing.JTextField txtPaid;
    private javax.swing.JTextField txtPhone;
    private javax.swing.JTextField txtSearch;
    // End of variables declaration//GEN-END:variables
}
